<%-- 
    Document   : Register
    Created on : Oct 18, 2012, 12:44:25 PM
    Author     : ANTV60287
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Register</title>
        <link href="Style.css" rel="stylesheet" type="text/css" />
        <script src="scrip/jquery-1.4.4.min.js" type="text/javascript"></script>
        <link href=""
    </head>
    <body>
<script type="text/javascript">
    $(function () {
        $('a').click(function () {
            $('a.active').removeClass('active'); // remove the class from the currently selected
            $(this).addClass('active'); // add the class to the newly clicked link
        });
    });
</script>
<script type="text/javascript">
            function isUserExist(Username){
                if(wiow.XMLHttpRequest){
                    xmlhttp=new XMLHttpRequest();
                }else{
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function(){
                    if(xmlhttp.readyState==4&&xmlhttp.status==200){
                        var isUserExist = xmlhttp.responseText;
                        if(isUserExist=='Existed'){
                            alert('User '+Username+' is exists!');
                        }
                    }
                }
                xmlhttp.open("GET","CusRegister?action=CheckUsername&username="+Username,true);
                xmlhttp.send(null);
            }
            function checkUsername(){
                var username = Username.value;
                var ReUser = /^[A-Za-z\d]$/
                reWhiteSpace = new RegExp(/\s/);
                if(username.length==0 || username==null){
                    document.getElementById('username').innerHTML= 'Vui lòng nhập tài khoản';
                    Username.style.background ='yellow';
                    return false;
                }
                if(!ReUser.test(username)){
                    document.getElementById('username').innerHTML= 'Tài khoản không được có ký tự đặc biệt.';
                    Username.style.background ='yellow';
                    return false;
                }
                if (reWhiteSpace.test(username)){
                    document.getElementById('username').innerHTML= 'Tài khoản không được có khoảng trắng';
                    Username.style.background ='yellow';
                    return false;
                }
                if(username.length<6 || username.length>=60 ){
                    document.getElementById('username').innerHTML= 'username phải lớn hơn 6 ký tự và bé hơn 60 ký tự';
                    Username.style.background ='yellow';
                    return false;
                }
                return true;
                
            }
            function checkPassword(){
                var password =  Password.value;
                var RePass = /^[A-Za-z\d]$/
                reWhiteSpace = new RegExp(/\s/);
                if(password.length==0 || password==null){
                    document.getElementById('password').innerHTML= 'Vui lòng nhập password.';
                    Password.style.background ='yellow';
                    return false;
                }
                if (reWhiteSpace.test(password)){
                    document.getElementById('password').innerHTML= 'Password không được có khoảng trắng.';
                    Password.style.background ='yellow';
                    return false;
                }
                if(!RePass.test(password)){
                    document.getElementById('password').innerHTML= 'Password không được có ký tự đặc biệt.';
                    Password.style.background ='yellow';
                    return false;
                }
                if(password.length<6 || password.length>=30 ){
                    document.getElementById('password').innerHTML= 'Password phải lớn hơn 6 ký tự và bé hơn 30 ký tự';
                    Password.style.background ='yellow';
                    return false;
                }
                return true;
            };
            function checkName(){
                var name = FullName.value;
                reWhiteSpace = new RegExp(/\s/);
                if(name.length==0 || name==null){
                    document.getElementById('fullname').innerHTML= 'Vui lòng nhập họ tên.';
                    FullName.style.background ='yellow';
                    return false;
                }
                if(name.length<6 || name.length>=60 ){
                    document.getElementById('fullname').innerHTML= 'Họ tên phải lớn hơn 6 ký tự và bé hơn 60 ký tự';
                    FullName.style.background ='yellow';
                    return false;
                }
                return true;
            };
            function isclear(textbox,labelId){
                textbox.value='';
                  textbox.style.background ='white';
                             document.getElementById(labelId).innerHTML= '';
            }

            function isFocus(textbox,labelId){
                  textbox.style.background ='white';
                             document.getElementById(labelId).innerHTML= '';
            }

            function checkAddress(){
                            var address =  Address.value;
                            reWhiteSpace = new RegExp(/\s/);
                            if(address.length==0 || address==null){
                                document.getElementById('address').innerHTML= 'Vui lòng nhập địa chỉ.';
                                Address.style.background ='yellow';
                                return false;
                            }
                            if( password.length>=100 ){
                                document.getElementById('address').innerHTML= 'Địa chỉ bé hơn 100 ký tự';
                                Address.style.background ='yellow';
                                return false;
                            }
                            return true;
                        };

            function checkTelephone(){
                var telephone =  Telephone.value;
                var anum=/(^\d+$)/;
                reWhiteSpace = new RegExp(/\s/);
                if(telephone.length==0 || telephone==null){
                    document.getElementById('telephone').innerHTML= 'Vui lòng nhập điện thoại.';
                    Telephone.style.background ='yellow';
                    return false;
                }
                if(!anum.test(telephone)){
                    document.getElementById('telephone').innerHTML= 'Điện thoại phải là số.';
                    Telephone.style.background ='yellow';
                    return false;
                }
                if( telephone.length>=12 ){
                    document.getElementById('telephone').innerHTML= 'Điện thoại phải bé hơn 12 ký tự';
                    Telephone.style.background ='yellow';
                    return false;
                }
                return true;
            };

            function checkEmail(){
                var email1 =  Email.value;
                reWhiteSpace = new RegExp(/\s/);
                var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
                if(email1.length==0 || email1==null){
                    document.getElementById('email').innerHTML= 'Vui lòng nhập email.';
                    Email.style.background ='yellow';
                    return false;
                }
                if(!filter.test(email1)){
                    document.getElementById('email').innerHTML= 'Email không hợp lệ.';
                    Email.style.background ='yellow';
                    return false;
                }
                return true;
            };
              

            function checkAll(){
                var error=0;
                if(!checkName()){
                    error=error+1;
                }  if(!checkEmail()){
                    error = error+1;
                }  if(!checkPassword()){
                    error = error+1;
                }  if(!checkUsername()){
                    error = error+1;
                }  if(!checkAddress()){
                    error = error+1;
                }  if(!checkTelephone()){
                    error = error+1;
                }
            if(error==0){
                document.registerForm.submit();
                return true;
            } else return false;

            };
            
</script>
<script type="text/javascript">
            function loadXML(dname)
            {
                try
                  {
                      xhttp=new XMLHttpRequest();
                  } catch(e) {
                    try{
                             xhttp=new ActiveXObject("Msxml2.XMLHTTP");
                    } catch(e){
                        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                xhttp.open("GET",dname,false);
                xhttp.send(null);
                return xhttp.responseXML;
            }
            function SearchFlower(categoryId){
                var xmlSearchHttp = null;
                try {
                    xmlSearchHttp = XMLHttpRequest();
                }catch(e){
                    try{
                        xmlSearchHttp = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e){
                        xmlSearchHttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                if(xmlSearchHttp==null){
                    alert("Your browser does not support AJAX!")
                    return;
                }
                try{
                    var url= "SearchFlower?action=SearchByCategory&id="+categoryId;
                    xmlSearchHttp.open("GET",url,true);
                    xmlSearchHttp.send(null);
                    xmlSearchHttp.onreadystatechange = function()
                    {
                        if(xmlSearchHttp.readyState==4 && xmlSearchHttp.status==200){
                            // lay response text
                            var response = xmlSearchHttp.responseText;
                            if(response =='Success') {
                                var xmlurl = '${pageContext.request.contextPath}' + "/XML/FlowerCategory"+categoryId+".xml";
                                var  xml = loadXML(xmlurl);
                                var xslurl = '${pageContext.request.contextPath}' +"/XSL/FlowerCategory.xsl";
                                var  xsl = loadXML(xslurl);
                                displayResult(xml, xsl, 'list-flower');
                            }
                        }
                    }
                }catch(e){
                    alert("error: "+ e);
                }
            }
            function DetailFlower(productID){
                var xmlSearchHttp = null;
                try {
                    xmlSearchHttp = XMLHttpRequest();
                }catch(e){
                    try{
                        xmlSearchHttp = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e){
                        xmlSearchHttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                if(xmlSearchHttp==null){
                    alert("Your browser does not support AJAX!")
                    return;
                }
                try{
                    var url= "SearchFlower?action=ViewDetail&id="+productID;
                    xmlSearchHttp.open("GET",url,true);
                    xmlSearchHttp.send(null);
                    xmlSearchHttp.onreadystatechange = function()
                    {
                        if(xmlSearchHttp.readyState==4 && xmlSearchHttp.status==200){
                            // lay response text
                            var response = xmlSearchHttp.responseText;
                            if(response =='SuccessDetail') {
                                var xmlurl = '${pageContext.request.contextPath}' + "/XML/Flower"+productID+".xml";
                                var  xml = loadXML(xmlurl);
                                var xslurl = '${pageContext.request.contextPath}' +"/XSL/ProductDetail.xsl";
                                var  xsl = loadXML(xslurl);
                                displayResult(xml, xsl, 'list-flower');
                            }
                        }
                    }
                }catch(e){
                    alert("error: "+ e);
                }
            }

            function displayResult(xml, xsl, divId) {
                if (window.ActiveXObject) {
                    var out = xml.transformNode(xsl);
                    document.getElementById(divId).innerHTML = out;
                } else {
                    var xsltProcessor = new XSLTProcessor();
                    xsltProcessor.importStylesheet(xsl);
                    resultDocument = xsltProcessor.transformToFragment(xml, document);
                    document.getElementById(divId).innerHTML="";
                    document.getElementById(divId).appendChild(resultDocument);
                }

            }
</script>
        <div id="Wrapper">
            <div id="Header">
                <div id="Hd-Top">
                    <div class="Logo">
                    </div><!--End Logo-->
                    <div id="Hd-Top-Right">
                        <div id="shoping-cart">
                            <p><strong>Shopping Cart:</strong> Now in your cart <strong>0 Items</strong></p>
                        </div><!--End shopping-cart-->
                        <div id="Login-form">
                            <form>
                                <input id="Txt-Username" type="text" placeholder="Tài khoản"/>
                                <input id="Txt-Password" type="password" placeholder="Mật khẩu"/>
                                <input class="btn-Login" type="submit" value="Login"/>
                            </form>
                            <a class="ForgotPw" href="">Quên mật khẩu?</a>
                            <p>|</p>
                            <a class="LinkRegister" href="">Đăng ký?</a>
                        </div><!--End Login-form-->
                    </div><!--End Hd-Top-Right-->
                </div><!--End Hd-Top-->
                <div id="Hd-Menu">
                    <ul class="Menu">
                        <li><a href="index.jsp">Trang chủ</a>|</li>
                        <li><a>Sản phẩm mới</a>|</li>
                        <li><a>Sản phẩm đặc biệt</a>|</li>
                        <li><a>Hướng dẫn mua hàng</a>|</li>
                        <li><a>Liên hệ</a></li>
                    </ul>
                    <div id="Search">
                        <p>Search:</p>
                        <form>
                            <input id="keyword" type="text" placeholder="Nhập từ khóa để tìm kiếm" />
                            <input id="btnsearch" type="submit" value="" />
                        </form>
                    </div><!--End Search-->
                </div><!--End Hd-Menu-->
                <div id="Hd-Bottom">
                    <div class="box-image1">
                    </div><!--End box-image-->
                    <div class="box-image2">
                    </div><!--End box-image-->
                    <div class="box-image3">
                    </div><!--End box-image-->
                </div><!--End Hd-Bottom-->
            </div><!--End Header-->
            <div id="Body">
                <div id="Category">
                    <p>Danh mục sản phẩm</p>
                    <ul class="ct-list">
                        <li><a class="active">Hoa Cưới</a></li>
                        <li><a>Hoa Sinh Nhật</a></li>
                        <li><a>Hoa Khai Trương</a></li>
                        <li><a>Hoa Tang Lễ</a></li>
                        <li><a>Hoa Tươi Cầm Tay</a></li>
                        <li><a>Hoa Tươi Valentine</a></li>
                    </ul>
                </div><!--End Catergory-->
                <div id="list-product">
                    <div id="register">
                        <h1>Đăng ký</h1>
                        <form class="form-register" method="POST" name="registerForm" action="Controller" onsubmit="return checkAll();">
                            <div class="ct-input">
                                <a>Tài khoản(*)</a><input type="text" id="Username" name="Username" onblur="checkUsername();"

                                                          onfocus="isFocus(this,'username')"/> <label id="username"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <a>Mật khẩu(*)</a><input type="password" name="Password" id="Password" onblur="checkPassword();" onfocus="isclear(this,'password')"/> <label id="password"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <a>Họ Tên(*)</a><input type="text" id="FullName" name="FullName" onblur="checkName();" onfocus="isFocus(this,'fullname')"/> <label id="fullname"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <a>Địa chỉ(*)</a><input type="text" id="Address" name="Address" onblur="checkAddress();" onfocus="isFocus(this,'address')"/> <label id="address"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <a>Điện thoại(*)</a><input type="text" id="Telephone" name="Telephone" onblur="checkTelephone();" onfocus="isFocus(this,'telephone')"/> <label id="telephone"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <a>Email(*)</a><input type="text" id="Email" name="Email" onblur="checkEmail();" onfocus="isFocus(this,'email')"/> <label id="email"></label>
                            </div><!--End label-->
                            <div class="ct-input">
                                <input type="submit" value="Register" name="action" class="btn-register"/>
                                <input type="RESET" value="Clear" class="btn-register" onclick="isclear(Username,'username');
                                    isclear(Password,'password');
                                    isclear(FullName,'fullname');
                                    isclear(Address,'address');
                                    isclear(Telephone,'telephone');
                                    isclear(Email,'email');"/>
                            </div><!--End label-->
                        </form>
                    </div><!--End register-->
                </div><!--End list-product-->
            </div><!--End Body-->
            <div id="Fotter">
                <p>@FPT-University XML Chicken Group</p>
            </div><!--End Fotter-->
        </div><!--End Wrapper-->
    </body>
</html>
